package com.copro.simple;

import org.ihelpuoo.util.Pager;

public class ScopePager {

	public ScopePager(Pager pager, int len) {
		this.pager = pager;
		this.len = len;
		this.max = len - 2;
		if (this.max < 1)
			throw new RuntimeException("ScopePager len must more than 3!");
	}

	private Pager pager;
	private int len;
	private int max;

	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public int getLen() {
		return len;
	}

	public void setLen(int maxLenght) {
		this.len = maxLenght;
	}

	public int getBeginPn() {
		if (null == pager)
			return 0;
		if (this.len <= 0)
			return 1;
		int n = pager.getPageNumber() / max;
		if (pager.getPageNumber() % max == 0)
			n--;
		int re = (n < 0 ? 0 : n) * max + 1;
		if (re > 1)
			re--;
		return re;
	}

	public int getEndPn() {
		if (null == pager)
			return 0;
		if (this.len <= 0)
			return pager.getPageCount();
		int re = this.getBeginPn() + this.len - 1;
		return re > pager.getPageCount() ? pager.getPageCount() : re;
	}
}
